package com.jonniespratley.codegen
{
	import com.jonniespratley.codegen.view.windows.DebugWindow;
	
	import flash.net.SharedObject;
	
	import mx.collections.ArrayCollection;
	import mx.core.Application;
	import mx.managers.PopUpManager;
	import mx.utils.ArrayUtil;
  
	public class CodeGenApplication extends Application
	{
		public var DEBUG_LOG_WINDOW:DebugWindow;
		public var codegenSettings:Object = {};
		public var codegenSO:SharedObject;
		[Bindable] public var SHARED_OBJECT_COLLECTION:ArrayCollection = new ArrayCollection();
		static public const CODEGEN_SETTINGS:String = 'CodeGenSettings';
		
		
		
		public function CodeGenApplication()
		{
			super();
			codegenSO = SharedObject.getLocal( CodeGenApplication.CODEGEN_SETTINGS );
			codegenSettings = codegenSO.data;
			
			DEBUG_LOG_WINDOW = new DebugWindow();
			SHARED_OBJECT_COLLECTION = new ArrayCollection( ArrayUtil.toArray( codegenSettings ) );	
		}
		
		public function openDebugWindow():void{
			PopUpManager.addPopUp( DEBUG_LOG_WINDOW, this );
			saveSetting( 'log', 'Opened Window' );		
		}
		
		public function saveSetting( name:String, value:Object ):void{
			 
			codegenSettings[ name ] = value;
			
			SHARED_OBJECT_COLLECTION.addItem( codegenSettings );
			codegenSO.data[CodeGenApplication.CODEGEN_SETTINGS] = codegenSettings;
			codegenSO.flush();
		}
		
		
		
		
	}
}